﻿
@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <link href="~/layuiMini/lib/layui-v2.6.3/css/layui.css" rel="stylesheet" />
    <link href="~/layuiMini/css/public.css" rel="stylesheet" />
    <title>修改密码</title>
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
    <div class="layui-form layuimini-form">
        <div class="layui-form-item">
            <label class="layui-form-label required">旧密码</label>
            <div class="layui-input-inline">
                <input type="password" name="OldPassword" lay-verify="required" lay-reqtext="旧密码不能为空" placeholder="请输入旧密码" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">新密码</label>
            <div class="layui-input-inline">
                <input type="password" name="NewPassword" lay-verify="required" lay-reqtext="新密码不能为空" placeholder="请输入新密码" value="" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label required">确认密码</label>
            <div class="layui-input-inline">
                <input type="password" name="NewPassword2" lay-verify="required" lay-reqtext="确认密码不能为空" placeholder="请输入确认密码" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
            </div>
        </div>
    </div>
    @*<script src="../../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>*@
    <script src="~/layuiMini/lib/layui-v2.6.3/layui.js"></script>
    <script>
        layui.use(['form'], function () {
            var form = layui.form,
                layer = layui.layer,
                $ = layui.$;


            //监听提交
            form.on('submit(saveBtn)', function (data) {

                //判断新密码两次是否正确
                if (data.field.NewPassword2 != data.field.NewPassword) {
                    layer.msg('新密码两次必须相同');
                } else if (data.field.NewPassword == data.field.OldPassword) {//新密码不能和旧密码相同
                    layer.msg('新密码要与旧密码不同');
                }
                else {
                    //异步请求修改密码
                    $.ajax({
                        url: 'http://localhost:31861/api/Login/EditPassword',
                        /*  data: data.field,*/
                        data:
                        {
                            oldPassword: data.field.OldPassword,
                            newPassword: data.field.NewPassword
                        },
                        type: 'post',
                        success: function (res) {
                            if (res.isSuccess) {
                                var index = layer.alert("修改成功", {
                                    title: '提示'
                                }, function () {

                                    // 关闭弹出层
                                    layer.close(index);
                                    var iframeIndex = parent.layer.getFrameIndex(window.name);
                                    parent.layer.close(iframeIndex);

                                    //去登录页
                                    window.location = '/Login/LoginView';
                                });
                            } else {
                                layer.msg(res.msg);
                            }
                        }
                    });
                }

                return false;
            });

        });

    </script>
</body>

</html>

